from PySide6.QtCore import QDateTime
from Devices.Chiot.BsDevs.ComDev.ComDevParser import ComDevParser

class DoorParser(ComDevParser):
    def ParseHeartbeat(msgValue, fullStatus):
        if not "stateValue" in msgValue:
            return True
        stateValue = msgValue["stateValue"]

        ret, value = DoorParser.GetIntProperty(stateValue, "door", "status")
        if ret:
            fullStatus.sensorStatus = value
            fullStatus.changeTime = QDateTime.currentSecsSinceEpoch()

        ret, value = DoorParser.GetIntProperty(stateValue, "electric", "powerWarn")
        if ret:
            fullStatus.powerWarn = value

        ret, value = DoorParser.GetIntProperty(stateValue, "electric", "batteryPercentage")
        if ret:
            fullStatus.batteryPercentage = value

        ret, value = DoorParser.GetIntProperty(stateValue, "checkStatus", "status")
        if ret:
            fullStatus.checkStatus = value

        ret, value = DoorParser.GetIntProperty(stateValue, "checkStatusTime", "timestamp")
        if ret:
            fullStatus.checkStatusTime = value

        return True
